<?php
/**
 * @author Amissah Gideon<kuulmek@yahoo.com>
 * @access public
 * @version 1.0
 */

$equipmentObj = ClassRegistry::init('Items');
$equipment_data = Set::combine($equipmentObj->find('all', array('fields' => array('id', 'name', 'amount'), 'conditions' => array('deleted' => 'n'), 'recursive' => -1)), '{n}.Items.id', '{n}.Items');
$equipmentOpt = array();
$global_equipment_data = array();
foreach ($equipment_data as $value) {
    $equipmentOpt[$value['id']] = $value['name'];
    $global_equipment_data[$value['id']] = array('name' => $value['name'], 'amount' => $value['amount']);
}

?>
<script type="text/javascript">
    var global_equipment_data = <?php echo json_encode($global_equipment_data); ?>;
    var gbl_customers_sales = <?php echo json_encode($customers_sales); ?>;
    //console.log(global_equipment_data);
</script>
<style type="text/css">
    @media only screen and (min-width: 768px) {
        /* Form layouts */
        .inline-label > .label{
            width: 180px;
        }

        .inline-label > .value{
            width: 450px;
            float: right;

        }
</style>
<!-- Main content -->
<section role="main" id="main">

    <!-- Header -->
    <?php echo $this->element('page_header'); ?>

    <div class="with-padding">
        <div class="columns">
            <div class="new-row-mobile twelve-columns six-columns-tablet twelve-columns-mobile">

                <h3 class="thin underline">Generate Client Statement and Amortization</h3>

                <table id="flex" style="display:none;"></table>

                <div style="display: none;">
                    <div id="credit-form-window" style="margin: 20px 5px 5px 5px;">
                        <fieldset class="fieldset">
                            <legend class="legend">Info</legend>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Officer In Charge :');?></label>
                                <span class="officer_incharge value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Sale Number :');?></label>
                                <span class="invoice_number value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Customer :');?></label>
                                <span class="name value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Items Purchased :');?></label>
                                <span class="items value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Vehicle No. :');?></label>
                                <span class="vehicle_no value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Date of Purchase :');?></label>
                                <span class="purchased_date value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Credit End Date :');?></label>
                                <span class="end_date value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Cost :');?></label>
                                <span class="cost value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Principal :');?></label>
                                <span class="principal value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Discount % :');?></label>
                                <span class="discount value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Deposited :');?></label>
                                <span class="deposit value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Duration in Month :');?></label>
                                <span class="duration_in_month value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Interest % :');?></label>
                                <span class="interest value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Total Interest :');?></label>
                                <span class="total_interest value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Monthly Installment :');?></label>
                                <span class="installment value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Total Instalments Paid :');?></label>
                                <span class="total_installment value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Principal Balance :');?></label>
                                <span class="balance value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Total Balance :');?></label>
                                <span class="tl_balance value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Last Paid Month :');?></label>
                                <span class="last_paid_date value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Next Installment Date :');?></label>
                                <span class="next_credit_date value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label"><?php echo __('Comments :');?></label>
                                <span class="comments value"></span>
                            </p>
                            <p class="button-height inline-label">
                                <label class="label">&nbsp;</label>
                                <button type="reset" class="button" id="credit-close-btn">
                                    <span class="button-icon anthracite-gradient"><span class="icon-cross-round"></span></span>
                                    Close
                                </button>
                            </p>
                        </fieldset>
                    </div>
                </div>

            </div>
        </div>
    </div>


    <!-- Repayment Section -->
    <div style="display: none;">
        <div id="repayment-window" style="padding:25px 20px 20px 20px;">
            <button type="reset" class="button data-type-menu" id="print-repayment-btn" action="repayment" data-type="print">
                <span class="button-icon anthracite-gradient"><span class="icon-printer"></span></span>
                Print
            </button>
            <button type="reset" class="button data-type-menu" id="export-repayment-btn" action="repayment" data-type="export">
                <span class="button-icon anthracite-gradient"><span class="icon-extract"></span></span>
                Export to Excel
            </button>

            <div style="margin: 10px;">Transactions in <strong id="transaction_currency"></strong></div>
            <div class="tdDiv thflotDiv" style="overflow: auto; max-height: 400px;">
                <table id="repayment_detail_flex" class="table table-bordered">
                    <thead>
                    <tr>
                        <th width="100">Month</th>
                        <th width="130">Repayment Schedule</th>
                        <th width="100">Expected</th>
                        <th width="100">Actual</th>
                        <th width="100">Outstanding</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>


    <!-- Armotization window -->
    <div style="display: none;">
        <div id="amortization-window" style="padding:25px 20px 20px 20px;">
            <button type="reset" class="button data-type-menu" id="print-amortization-btn" action="amortization" data-type="print">
                <span class="button-icon anthracite-gradient"><span class="icon-printer"></span></span>
                Print
            </button>
            <button type="reset" class="button data-type-menu" id="export-amortization-btn" action="amortization" data-type="export">
                <span class="button-icon anthracite-gradient"><span class="icon-extract"></span></span>
                Export to Excel
            </button>

            <div style="margin: 20px;">
                <table>
                    <tr><td>Loan Amount (pv)</td><td><span id="loan_amt"></span></td></tr>
                    <tr><td>Inerest Rate (rate)</td><td><span id="int_rate"></span></td></tr>
                    <tr><td>Total # of Period (Nper)</td><td><span id="tl_period"></span></td></tr>
                    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                    <tr><td>Payment per Period</td><td><span id="pay_per_period"></span></td></tr>
                    <tr><td>Total Interest Paid</td><td><span id="tl_int_paid"></span></td></tr>
                    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                    <tr><td>Total Payment</td><td><span id="tl_payment"></span></td></tr>
                </table>
            </div>

            <div class="tdDiv thflotDiv" style="overflow: auto; max-height: 300px;">
                <table id="amortization_detail_flex" class="table table-bordered">
                    <thead>
                    <tr>
                        <th width="100">Period</th>
                        <th width="130">Payment Amount</th>
                        <th width="100">Interest</th>
                        <th width="100">Principal</th>
                        <th width="100">Balance</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>

</section>
<!-- End main content -->

<!-- Side tabs shortcuts -->
<?php echo $this->element('side_tabs_shortcuts'); ?>
<!-- Sidebar/drop-down menu -->
<?php echo $this->element('right_side_infos'); ?>


<!-- Users URL -->
<input type="hidden" id="table-url" value="<?php echo $this->Html->url(array('controller' => 'CreditControl', 'action' => 'get')); ?>"/>
<input type="hidden" id="add-edit-url" value="<?php echo $this->Html->url(array('controller' => 'CreditControl', 'action' => 'add')); ?>"/>
<input type="hidden" id="load-user-url" value="<?php echo $this->Html->url(array('controller' => 'CreditControl', 'action' => 'load')); ?>"/>
<input type="hidden" id="delete-url" value="<?php echo $this->Html->url(array('controller' => 'CreditControl', 'action' => 'delete_')); ?>"/>
<input type="hidden" id="repayment-url" value="<?php echo $this->Html->url(array('controller' => 'CreditControl', 'action' => 'repayment_details')); ?>"/>
<input type="hidden" id="amortization-url" value="<?php echo $this->Html->url(array('controller' => 'CreditControl', 'action' => 'amortization')); ?>"/>


<?php
echo $this->Html->script('setup.js');

/** Template functions **/
echo $this->Html->script('developr.input.js');
echo $this->Html->script('developr.message.js');
echo $this->Html->script('developr.modal.js');
echo $this->Html->script('developr.navigable.js');
echo $this->Html->script('developr.notify.js');
echo $this->Html->script('developr.scroll.js');
echo $this->Html->script('developr.progress-slider.js');
echo $this->Html->script('developr.tooltip.js');
echo $this->Html->script('developr.confirm.js');
echo $this->Html->script('developr.agenda.js');
echo $this->Html->script('developr.tabs.js');

echo $this->Html->script('libs/tinycon.min.js');
echo $this->Html->script('jquery.thfloat-0.3.min.js');
echo $this->Html->script('custom-scripts/credit.js');
?>


<!--<div class="credit-pane">
    <div class="pane-header">
        <?php /* echo __('Credit Management'); */?>
    </div>

    <table id="creditflex" style="display:none;"></table>

    <div style="display: none;">
        <div id="credit-form-window" style="margin: 20px 5px 5px 5px;">
            <table cellspacing="10" width="360px">
                <tr>
                    <td><?php /*echo __('Invoice Number :');*/?> </td>
                    <td>
                        <span class="invoice_number"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /*echo __('Customer :');*/?> </td>
                    <td>
                        <span class="name"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Items Purchased :');*/?> </td>
                    <td>
                        <span class="items"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /*echo __('Vehicle No. :');*/?> </td>
                    <td>
                        <span class="vehicle_no"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Date of Purchase:');*/?> </td>
                    <td>
                        <span class="purchased_date"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Credit End Date:');*/?> </td>
                    <td>
                        <span class="end_date"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Cost:');*/?></td>
                    <td>
                        <span class="cost"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Principal:');*/?></td>
                    <td>
                        <span class="principal"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Discount %:');*/?></td>
                    <td>
                        <span class="discount"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Deposited:');*/?></td>
                    <td>
                        <span class="deposit"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Duration in Month :');*/?> </td>
                    <td>
                        <span class="duration_in_month"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Interest %:');*/?></td>
                    <td>
                        <span class="interest"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Total Interest:');*/?></td>
                    <td>
                        <span class="total_interest"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Monthly Installment:');*/?></td>
                    <td>
                        <span class="installment"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Total Instalments Paid:');*/?></td>
                    <td>
                        <span class="total_installment"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Principal Balance:');*/?></td>
                    <td>
                        <span class="balance"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Total Balance:');*/?></td>
                    <td>
                        <span class="tl_balance"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Last Paid Month:');*/?></td>
                    <td>
                        <span class="last_paid_date"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Next Credit Date:');*/?></td>
                    <td>
                        <span class="next_credit_date"></span>
                    </td>
                </tr>
                <tr>
                    <td><?php /* echo __('Comments:');*/?></td>
                    <td>
                        <span class="comments"></span>
                    </td>
                </tr>
                <tr>
                    <td>

                    </td>
                    <td>
                        <button type="reset" class="cancel" id="credit-close-btn">&nbsp;Close</button>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <!-- Repayment Section --
    <div style="display: none;">
        <div id="repayment-window" style="padding:25px 20px 20px 20px;">
            <button type="reset" class="data-type-menu" id="print-repayment-btn" action="repayment" data-type="print">&nbsp;Print</button>
            <button type="reset" class="data-type-menu" id="export-repayment-btn" action="repayment" data-type="export">&nbsp;Export to Excel</button>
            <div style="margin-bottom: 10px;">Transactions in <strong id="transaction_currency"></strong></div>
            <div class="tdDiv thflotDiv" style="overflow: auto; max-height: 400px;">
                <table id="repayment_detail_flex" class="table table-bordered thfloat">
                    <thead>
                    <tr>
                        <th width="100">Month</th>
                        <th width="130">Repayment Schedule</th>
                        <th width="100">Expected</th>
                        <th width="100">Actual</th>
                        <th width="100">Outstanding</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>


    <!-- Armotization window --
    <div style="display: none;">
        <div id="amortization-window" style="padding:25px 20px 20px 20px;">
            <button type="reset" class="data-type-menu" id="print-amortization-btn" action="amortization" data-type="print">&nbsp;Print</button>
            <button type="reset" class="data-type-menu" id="export-amortization-btn" action="amortization" data-type="export">&nbsp;Export to Excel</button>
            
            <div style="margin-bottom: 15px;">
                <table>
                    <tr><td>Loan Amount (pv)</td><td><span id="loan_amt"></span></td></tr>
                    <tr><td>Inerest Rate (rate)</td><td><span id="int_rate"></span></td></tr>
                    <tr><td>Total # of Period (Nper)</td><td><span id="tl_period"></span></td></tr>
                    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                    <tr><td>Payment per Period</td><td><span id="pay_per_period"></span></td></tr>
                    <tr><td>Total Interest Paid</td><td><span id="tl_int_paid"></span></td></tr>
                    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                    <tr><td>Total Payment</td><td><span id="tl_payment"></span></td></tr>
                </table>
            </div>
            
            <div class="tdDiv thflotDiv" style="overflow: auto; max-height: 300px;">
                <table id="amortization_detail_flex" class="table table-bordered thfloat">
                    <thead>
                    <tr>
                        <th width="100">Period</th>
                        <th width="130">Payment Amount</th>
                        <th width="100">Interest</th>
                        <th width="100">Principal</th>
                        <th width="100">Balance</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>

</div>-->



<!-- Users URL -->
